<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'part-action-form',
	'enableAjaxValidation'=>true,
	'clientOptions' => array('validateOnSubmit' => true,
   							 'validateOnChange' => false)
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'serviceId'); ?>
		<?php echo CHtml::link('Service #'.$model->serviceId, 
					array('service/view','id'=>$model->serviceId));?>
	</div>

	<div class="row">	
		<?php 
		
		if($model->isNewRecord){
			?>
			<div class="row">
	<?php echo CHtml::label("Choose Part",'partSelector'); ?>
	<?php 
			  $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
			     'name'=>'partSelector',
			     'sourceUrl'=>array('ajaxSearchPart'),
			     'options'=>array(
			         'showAnim'=>'fold',
              		 'minLength'=>2,
                     'select'=>'js:function(event,ui){
                     	$("#'.CHtml::activeId($model, "partId").'").val(ui.item.id);
                     	$("#partNameModel").html(ui.item.name+"("+ui.item.num+")"+" is selected!");
                     	$("#partInfo").show("slow");
                     }',
				  ),
			      'htmlOptions'=>array(
			      	'style'=>'width:300px;'  
			       ),
			  ));
    ?>
    <?php echo $form->hiddenField($model,'partId'); ?>
    <div class="hint">Input 2 letters of the part name or part number to select a part.</div>
    <?php echo $form->error($model,'partId');?>
	</div>
	<div id="partInfo" style="display: none;">
		<div class="row" style="margin-left:160px">
			<?php echo CHtml::tag('span',array('id'=>'partNameModel'),'');?> 
		</div>
	</div>

		<?php 
		}else{
			echo $form->labelEx($model,'partId');
			echo CHtml::link($model->part->name."(".$model->part->num.")", 
					array('sparePart/view','id'=>$model->partId), array("target"=>"_blank"));
		}?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'requestQty'); ?>
		<?php echo $form->textField($model,'requestQty'); ?>
		<?php echo $form->error($model,'requestQty'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'usedQty'); ?>
		<?php echo $form->textField($model,'usedQty'); ?>
		<?php echo $form->error($model,'usedQty'); ?>
	</div>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->